package com.example.filesave.sql;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.example.filesave.util.L;

import java.sql.ResultSet;

/**
 * Created by Administrator on 2018/1/17.
 */

public class MyOpenHelper extends SQLiteOpenHelper {

    public static final String CREATE_BOOK = "create table book ( " +
            "id integer primary key autoincrement," +
            "author text," +
            "price real," +
            "pages integer," +
            "name text)";

    public static final String CREATE_CATEGORY = "create table category(" +
            "id integer primary key autoincrement," +
            "category_name text," +
            "category_code intager)";

    private Context mcontext;

    public MyOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        mcontext = context;

    }


    //  创建数据库时调用
    @Override
    public void onCreate(SQLiteDatabase db) {
        L.d("创建数据库");
        db.execSQL(CREATE_BOOK);
        db.execSQL(CREATE_CATEGORY);
    }
    // 升级数据库时调用
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        L.d("升级数据库");
//        db.execSQL("drop table if exists book");
//        db.execSQL("drop table if exists category");
        onCreate(db);
    }

}
